<?php
namespace Home\Controller;
use User\Api\UserApi;

class ProposeController extends HomeController {
    public function index(){
        $uid = is_login();
        if($uid){
            $modelPropose = M('Propose');
            $where['uid'] = $uid;
            $count = $modelPropose->where($where)->count();
            $Page = new \Think\Page($count,10);
            $res = $modelPropose->where($where)->limit($Page->firstRow,$Page->listRows)->order('posttime desc')->select();
            $this->assign('_list',$res);
            $this->assign('_page',$Page);
        }
        
        $this->display();
    }
    
    public function save(){
        $uid = is_login();
        if($uid){
        }else{
            //验证码验证
            $verify = I('verify');
            if(empty($verify)){
                $this->error('验证码不能为空！');
            }
                /* 调用UC登录接口登录 */
            $user = new UserApi;
            $uid = $user->login($mobile, $verify, 5);
            if(0 < $uid){ //UC登录成功
                /* 登录用户 */
                $Member = D('Member');
                if($Member->login($uid)){ //登录用户
                } else {
                    $this->error($Member->getError());
                }
            }
        }
        $modelPropose = M('Propose');
        $title = I('title');
        if(empty($title)){
            $this->error('问题标题不能为空！');
        }
        $question = I('question');
        if(empty($question)){
            $this->error('问题内容不能为空！');
        }
        $data['title'] = $title;
        $data['question'] = $question;
        $data['uid'] = $uid;
        $modelPropose->add($data);
        $this->success('投诉建议递交成功！');
    }
}